import axios from "axios";
import { baseURL } from "../config";
import Notification from "../components/notification/Notification";

const token = localStorage.getItem('token')

const instance = axios.create({
  baseURL,
  headers:{
    "Authorization": `Bearer ${token}`,
  },
  timeout:10000,
})

//添加请求拦截器
instance.interceptors.request.use(config => {
  //在发送请求之前做什么
  //配置请求头
  
  return config;
},error => {
  //对请求错误做什么
  console.log(error);
});

//添加响应拦截器
instance.interceptors.response.use( async res => {
  //对相应数据做什么
  
  return res.data;
}, async err => {
  //对响应错误做些什么
  // console.log("error:",err);
})

export default instance;

